﻿using System.Collections.Generic;
using System.Data;
using System;
using SXT.Party.WomenAndChildrens.Model;

namespace ZHDJ.MobileInterface
{
    public partial class InsertWCDoctorDianZan : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            WCDoctorDianZanOutParam result = new WCDoctorDianZanOutParam();
            WCDoctorDianZanInParam param = new WCDoctorDianZanInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as WCDoctorDianZanInParam;


                if (string.IsNullOrEmpty(param.ExpertsID))
                {
                    result.code = "0";
                    result.desc = "专家ID不能为空";

                    isFlag = false;
                }

                ///专家是否存在
                if (!InterfaceHelper.IsHaveDoctor(param.ExpertsID))
                {
                    result.code = "0";
                    result.desc = "专家ID不存在，请确认后重试。";

                    isFlag = false;
                }
                if (isFlag)
                {
                    //检查是否已经点赞   true 不存在  false 存在
                    if (PartyWCPraseCs.CheckDianZan(param.ExpertsID, param.user_id, "true", "DoctorInterlocution"))
                    {
                        if (PartyWCPraseCs.InsertDianZan(param.ExpertsID, param.user_id, "DoctorInterlocution", "true"))
                        {
                            result.code = "1";
                            result.desc = "点赞成功。";
                        }
                        else
                        {
                            result.code = "0";
                            result.desc = "点赞失败";
                        }
                    }
                    else
                    {
                        result.code = "0";
                        result.desc = "每条信息每人只能点赞一次。";
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作不成功！";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-InsertWCDoctorDianZan", SerializeHelper.JsonSerializer<WCDoctorDianZanInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<WCDoctorDianZanInParam, WCDoctorDianZanOutParam>();
            else
                SafeProcessRequest<WCDoctorDianZanInParam, WCDoctorDianZanOutParam>();
        }
    }

    #region 请求参数
    public class WCDoctorDianZanInParam
    {
        /// <summary>
        ///	用户ID 
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        ///	专家ID 必须
        /// </summary>
        public string ExpertsID
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class WCDoctorDianZanOutParam
    {
        public WCDoctorDianZanOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion
}